package org.demos.springaiargdemo1.config;

import org.elasticsearch.client.RestClient;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.ai.vectorstore.elasticsearch.ElasticsearchVectorStore;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.config.CorsRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer;

@Configuration
public class AIConfig implements WebFluxConfigurer {

    @Value("${spring.ai.vectorstore.elasticsearch.index-name}")
    private String indexName;

    /**
     * 配置CORS，允许前端应用访问API
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .allowedHeaders("*");
    }

//    @Bean
//    public VectorStore vectorStore(EmbeddingModel embeddingModel, RestClient restClient) {
//        return new ElasticsearchVectorStore.Builder(restClient,embeddingModel)
//                .build();
//    }
}
